/**************************************************************************
 * $RCSfile: MetaPlatformClientContext.java,v $  $Revision: 1.2 $  $Date: 2009/01/06 02:09:00 $
 *
 * $Log: MetaPlatformClientContext.java,v $
 * Revision 1.2  2009/01/06 02:09:00  @author simplefan
 * *** empty log message ***
 *
 * Revision 1.1  2009/01/04 10:03:20  @author simplefan
 * *** empty log message ***
 *
 **************************************************************************/
package com.simplefan.meta.determine.client.desktop;

import java.util.Properties;

import com.simplefan.framework.client.desktop.service.ServiceLoader;
import com.simplefan.meta.determine.client.desktop.service.MetaPlatformServiceFacade;
import com.simplefan.meta.determine.client.desktop.service.MetaPlatformServiceFactory;
import com.simplefan.system.client.desktop.AbstractClientContext;

/**
 * @author K
 */
public class MetaPlatformClientContext  extends AbstractClientContext<MetaPlatformServiceFactory, MetaPlatformServiceFacade> {

  private static MetaPlatformClientContext clientContext;

  public MetaPlatformClientContext(Properties configuration) {
    super(configuration);
  }

  public MetaPlatformClientContext() {
    this(new Properties());
  }
  
  public synchronized static MetaPlatformClientContext getInstance() {
    if(clientContext == null)
      clientContext = new MetaPlatformClientContext();
    return clientContext;
  }
  
  public synchronized static AbstractClientContext<MetaPlatformServiceFactory, MetaPlatformServiceFacade> getInstance(Properties configuration) {
    if(clientContext == null)
    {
      clientContext = new MetaPlatformClientContext(configuration);
    }
    return clientContext;
  }    

  @Override
  protected MetaPlatformServiceFacade loadServiceFacade() throws Exception {
    MetaPlatformServiceFacade facade = new MetaPlatformServiceFacade();
    facade.setServiceFactory(getServiceFactory());
    return facade;
  }

  @Override
  protected MetaPlatformServiceFactory loadServiceFactory() throws Exception {
    ServiceLoader serviceLoader = getServiceLoader();
    return new MetaPlatformServiceFactory(serviceLoader);
  }
  
  @Override
  protected String getLocalServiceLoaderBeanName() {
    return "metaplatformLocalServiceLoader";
  }  
}
